{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 18,
   "metadata": {},
   "outputs": [],
   "source": [
    "import pandas as pd\n",
    "import numpy as np\n",
    "from sklearn.linear_model import LinearRegression\n",
    "from sklearn.preprocessing import  PolynomialFeatures\n",
    "import matplotlib.pyplot as plt"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# 处理数据并计算出修正系数g(s)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 19,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>瞄准刻度</th>\n",
       "      <th>距离</th>\n",
       "      <th>夹角</th>\n",
       "      <th>命中刻度</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>12.7</td>\n",
       "      <td>14.87</td>\n",
       "      <td>67</td>\n",
       "      <td>13.8</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>9.2</td>\n",
       "      <td>11.37</td>\n",
       "      <td>88</td>\n",
       "      <td>11.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>5.2</td>\n",
       "      <td>6.81</td>\n",
       "      <td>59</td>\n",
       "      <td>9.5</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>8.3</td>\n",
       "      <td>9.99</td>\n",
       "      <td>67</td>\n",
       "      <td>11.5</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>8.2</td>\n",
       "      <td>9.41</td>\n",
       "      <td>86</td>\n",
       "      <td>14.7</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "   瞄准刻度     距离  夹角  命中刻度\n",
       "0  12.7  14.87  67  13.8\n",
       "1   9.2  11.37  88  11.0\n",
       "2   5.2   6.81  59   9.5\n",
       "3   8.3   9.99  67  11.5\n",
       "4   8.2   9.41  86  14.7"
      ]
     },
     "execution_count": 19,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df = pd.read_excel(\"./data.xlsx\")\n",
    "df.head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 20,
   "metadata": {},
   "outputs": [],
   "source": [
    "# 网上说距离大于12公里时误差很小，经过检验确实如此\n",
    "gb = df.groupby(df.距离>12)[\"距离\"]\n",
    "df = df.drop(gb.groups[True],axis=0)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "根据夹角还原出真实值"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 21,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "1.9629909152447274"
      ]
     },
     "execution_count": 21,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "def fitDistance(s,theta):\n",
    "    theta = np.radians(90-theta)\n",
    "    s = s/np.cos(theta)\n",
    "    return s\n",
    "fitDistance(1.7,60)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 22,
   "metadata": {},
   "outputs": [],
   "source": [
    "df[\"瞄准刻度\"] = fitDistance(df[\"瞄准刻度\"],df[\"夹角\"])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 23,
   "metadata": {},
   "outputs": [],
   "source": [
    "df[\"命中刻度\"] = fitDistance(df[\"命中刻度\"],df[\"夹角\"])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 24,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>瞄准刻度</th>\n",
       "      <th>距离</th>\n",
       "      <th>夹角</th>\n",
       "      <th>命中刻度</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>9.205608</td>\n",
       "      <td>11.37</td>\n",
       "      <td>88</td>\n",
       "      <td>11.006705</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>6.066494</td>\n",
       "      <td>6.81</td>\n",
       "      <td>59</td>\n",
       "      <td>11.083017</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>9.016791</td>\n",
       "      <td>9.99</td>\n",
       "      <td>67</td>\n",
       "      <td>12.493144</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>8.220024</td>\n",
       "      <td>9.41</td>\n",
       "      <td>86</td>\n",
       "      <td>14.735896</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5</th>\n",
       "      <td>7.061342</td>\n",
       "      <td>7.60</td>\n",
       "      <td>67</td>\n",
       "      <td>14.665865</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "       瞄准刻度     距离  夹角       命中刻度\n",
       "1  9.205608  11.37  88  11.006705\n",
       "2  6.066494   6.81  59  11.083017\n",
       "3  9.016791   9.99  67  12.493144\n",
       "4  8.220024   9.41  86  14.735896\n",
       "5  7.061342   7.60  67  14.665865"
      ]
     },
     "execution_count": 24,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df.head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 25,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>瞄准刻度</th>\n",
       "      <th>距离</th>\n",
       "      <th>夹角</th>\n",
       "      <th>命中刻度</th>\n",
       "      <th>位移倍数</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>9.205608</td>\n",
       "      <td>11.37</td>\n",
       "      <td>88</td>\n",
       "      <td>11.006705</td>\n",
       "      <td>1.146739</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>6.066494</td>\n",
       "      <td>6.81</td>\n",
       "      <td>59</td>\n",
       "      <td>11.083017</td>\n",
       "      <td>1.620192</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>9.016791</td>\n",
       "      <td>9.99</td>\n",
       "      <td>67</td>\n",
       "      <td>12.493144</td>\n",
       "      <td>1.289157</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>8.220024</td>\n",
       "      <td>9.41</td>\n",
       "      <td>86</td>\n",
       "      <td>14.735896</td>\n",
       "      <td>1.594512</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5</th>\n",
       "      <td>7.061342</td>\n",
       "      <td>7.60</td>\n",
       "      <td>67</td>\n",
       "      <td>14.665865</td>\n",
       "      <td>1.807692</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "       瞄准刻度     距离  夹角       命中刻度      位移倍数\n",
       "1  9.205608  11.37  88  11.006705  1.146739\n",
       "2  6.066494   6.81  59  11.083017  1.620192\n",
       "3  9.016791   9.99  67  12.493144  1.289157\n",
       "4  8.220024   9.41  86  14.735896  1.594512\n",
       "5  7.061342   7.60  67  14.665865  1.807692"
      ]
     },
     "execution_count": 25,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 获取位移\n",
    "df[\"位移倍数\"] = df[\"命中刻度\"] - df[\"瞄准刻度\"]\n",
    "# 似乎是记录落弹点时受特效影响，记录的位移偏大\n",
    "df[\"位移倍数\"] = df[\"位移倍数\"].apply(lambda x:x*.75)\n",
    "df[\"位移倍数\"] = df[\"位移倍数\"] / df[\"瞄准刻度\"] + 1\n",
    "df.head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 26,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([[11.37      ,  1.14673913],\n",
       "       [ 6.81      ,  1.62019231],\n",
       "       [ 9.99      ,  1.28915663],\n",
       "       [ 9.41      ,  1.5945122 ],\n",
       "       [ 7.6       ,  1.80769231],\n",
       "       [10.71      ,  1.23901099],\n",
       "       [ 9.57      ,  1.43670886],\n",
       "       [ 8.37      ,  1.95769231],\n",
       "       [ 8.47      ,  1.68478261],\n",
       "       [10.95      ,  1.        ],\n",
       "       [ 2.05      ,  8.453125  ],\n",
       "       [ 5.11      ,  4.5       ],\n",
       "       [ 4.99      ,  4.3125    ],\n",
       "       [ 4.43      ,  4.79545455],\n",
       "       [ 4.83      ,  5.171875  ],\n",
       "       [ 6.14      ,  3.82954545],\n",
       "       [ 6.98      ,  2.92857143],\n",
       "       [ 6.38      ,  2.815     ],\n",
       "       [ 6.37      ,  2.89      ],\n",
       "       [ 7.97      ,  2.0125    ],\n",
       "       [ 5.23      ,  3.78289474]])"
      ]
     },
     "execution_count": 26,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df2 = df.drop(labels=[\"瞄准刻度\",\"夹角\",\"命中刻度\"],axis = 1)\n",
    "arr = np.array(df2)\n",
    "arr"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# 进行拟合"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 27,
   "metadata": {},
   "outputs": [],
   "source": [
    "x = np.vstack([arr,[13,1],[13,1],[13,1]])# 试图让拟合结果在12公里时为1"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 28,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "LinearRegression(copy_X=True, fit_intercept=True, n_jobs=None, normalize=False)"
      ]
     },
     "execution_count": 28,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "poly_reg =PolynomialFeatures(degree=2)\n",
    "X_ploy =poly_reg.fit_transform(x[:,:1])\n",
    "lin_reg=LinearRegression()\n",
    "lin_reg.fit(X_ploy,x[:,1:])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 29,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "(12, 1)"
      ]
     },
     "execution_count": 29,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "x = np.linspace(1, 12, 12)\n",
    "x = x.reshape([x.shape[0],1])\n",
    "x.shape"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 30,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([[10.02046639],\n",
       "       [ 8.36818888],\n",
       "       [ 6.88196255],\n",
       "       [ 5.56178741],\n",
       "       [ 4.40766344],\n",
       "       [ 3.41959064],\n",
       "       [ 2.59756903],\n",
       "       [ 1.9415986 ],\n",
       "       [ 1.45167934],\n",
       "       [ 1.12781126],\n",
       "       [ 0.96999436],\n",
       "       [ 0.97822864]])"
      ]
     },
     "execution_count": 30,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "X_ploy =poly_reg.fit_transform(x)\n",
    "y_pred = lin_reg.predict(X_ploy)\n",
    "y_pred"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 31,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "<matplotlib.lines.Line2D at 0x1c83bb193c8>"
      ]
     },
     "execution_count": 31,
     "metadata": {},
     "output_type": "execute_result"
    },
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAXAAAAD4CAYAAAD1jb0+AAAAOXRFWHRTb2Z0d2FyZQBNYXRwbG90bGliIHZlcnNpb24zLjQuMiwgaHR0cHM6Ly9tYXRwbG90bGliLm9yZy8rg+JYAAAACXBIWXMAAAsTAAALEwEAmpwYAAAjrElEQVR4nO3dd3xUVf7/8deZ9ARCCCEIhBC6IiVAUIoFFV0LCrugiAFFUext1V3rlp9rWb8WVFakqLAQFURcxcWGDZQioUuNEHpLwQAJ6ef3x8QVQoIhmeRmZt7Px4PHzNx7Z+5n8hjeOTlz7jnGWouIiHgfl9MFiIhI9SjARUS8lAJcRMRLKcBFRLyUAlxExEsF1uXJYmJibEJCQl2eUkTE6y1fvjzTWtu0/PY6DfCEhARSU1Pr8pQiIl7PGLO9ou3qQhER8VIKcBERL6UAFxHxUgpwEREvpQAXEfFSCnARES/1mwFujHnTGHPAGPPjMduijTFfGGPSym4b126ZIiJSXlVa4FOBS8ttexj40lrbAfiy7HGt+WrjfmYu21GbpxAR8Tq/GeDW2gVAdrnNg4FpZfenAUM8W9Zx5+ftpTt4/D8/smrnz7V1GhERr1PdPvBm1tq9Zff3Ac0qO9AYM9YYk2qMSc3IyDjlExljeP7q7sQ2DOXOlBUczC2sZskiIr6lxl9iWveSPpUu62OtnWStTbLWJjVtesKl/FUSFR7MhJE9yThcwH0zV1FaqlWERESqG+D7jTHNAcpuD3iupIp1i4viL1d25tvNGfzr659q+3QiIvVedQP8I+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Y43A9NWKtXQBkl9s8GJhWdn8aMKQua/KUit6btfZza21x2cMlQJwnzqUAr4QxJgHoASx1uBRPGgf8CSh1uI7a0AbIAN4q6yKaYoyJcLooT7DW7gaeB3YAe4Eca+3nzlZVK5pZa/eW3d8HNHOymFp0E/CJJ15IAV4BY0wD4H3gPmvtIafr8QRjzCDggLV2udO11JJAoCcwwVrbA8jFe/8EP05ZX/Bg3L+kWgARxpiRzlZVu6x7fLPPjXE2xjyGu6s2xROvpwAvxxgThDu8U6y1c5yux4P6A1cZY7YB7wIXGmNmOFuSR+0Cdllrf/mLaTbuQPcFA4F0a22GtbYImAP0c7im2rDfGNMcoOz2gMP1eJQxZjQwCEi2HroARwF+DGOMwd2HusFa+6LT9XiStfYRa22ctTYB9xdgX1lrfaYVZ63dB+w0xnQq23QRsN7BkjxpB9DHGBNe9hm9CB/5gracj4Abyu7fAHzoYC0eZYy5FHf35VXW2jxPva4C/Hj9gVG4W6eryv5d7nRRUmV3AynGmDVAIvC0s+V4RtlfFbOBFcBa3P9vvfqyc2PMO8BioJMxZpcxZgzwLHCxMSYN918dzzpZY3VV8t7GAw2BL8py5XWPnEuX0ouIeCe1wEVEvJQCXETESynARUS8lAJcRMRLKcBFRLyUAlxExEspwEVEvNT/Bzv/Ecs/oJ1CAAAAAElFTkSuQmCC\n",
      "text/plain": [
       "<Figure size 432x288 with 1 Axes>"
      ]
     },
     "metadata": {
      "needs_background": "light"
     },
     "output_type": "display_data"
    }
   ],
   "source": [
    "plt.plot(x,y_pred)\n",
    "for num in arr:\n",
    "    plt.scatter(num[0], num[1],color=\"red\")\n",
    "plt.axhline(y=1, c=\"black\",ls=\"--\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 34,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "线性拟合系数：[[ 0.         -1.90135427  0.08302559]]\n",
      "线性拟合截距[11.83879507]\n",
      "距离为5时输入参数[[ 1.  5. 25.]],输出：[[4.40766344]]\n"
     ]
    }
   ],
   "source": [
    "print(f\"线性拟合系数：{lin_reg.coef_}\")\n",
    "print(f\"线性拟合截距{lin_reg.intercept_}\")\n",
    "i = 5\n",
    "X_ploy =poly_reg.fit_transform([[i]])\n",
    "y_pred = lin_reg.predict(X_ploy)\n",
    "print(f\"距离为{i}时输入参数{X_ploy},输出：{lin_reg.predict(X_ploy)}\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 36,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "4.407663470000001"
      ]
     },
     "execution_count": 36,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "def compute(s):\n",
    "    return np.power(s,2)*0.08302559+s*(-1.90135427)+11.83879507\n",
    "compute(5)"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.6"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 4
}
